﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class WayPoint : MonoBehaviour
{
    public WAYPOINTACT_ID m_ActID = WAYPOINTACT_ID.ACT_MOVE;

    public BASEUNIT_STATE m_ChangeAnimID = BASEUNIT_STATE.IDLE;
    public float m_fWayPointEndTime = -1.0f;
    public float m_fChangeAngle = -1.0f;

    public int m_iSceneID = 0;
    public int m_iLog_Start = 0;
    public int m_iLog_End = 0;

    public float m_fCurrentTime = 0.0f;

    [HideInInspector]public bool m_bPlayTimer;

    public List<EventDelegate > TriggerOnFinished = new List<EventDelegate>();

    void Start()
    {
        m_bPlayTimer = false;
    }

    void Update()
    {
        if (m_bPlayTimer)
            m_fCurrentTime += Time.deltaTime;
        else
            m_fCurrentTime = 0;
    }

    public bool WayPointEndCheck(Vector3 vecActerPos)
    {
        //Distance Chk (Is Arrive?)
        if (m_ActID == WAYPOINTACT_ID.ACT_MOVE)
        {
            if (0.01f > Vector3.Distance(transform.position, vecActerPos))
            {

                if (TriggerOnFinished.Count > 0)
                {
                    EventDelegate.Execute(TriggerOnFinished);
                }

                return true;
            }
        }

        if (m_ActID == WAYPOINTACT_ID.ACT_CHAT)
        {
            if (m_fWayPointEndTime == -1.0f && m_bPlayTimer)
            {
                if (TriggerOnFinished.Count > 0)
                {
                    EventDelegate.Execute(TriggerOnFinished);
                }

                return true;
            }
        }

        if(m_fWayPointEndTime != -1.0f)
        {
            if ((m_fWayPointEndTime <= m_fCurrentTime))
            {
                if (TriggerOnFinished.Count > 0)
                {
                    EventDelegate.Execute(TriggerOnFinished);
                }
                return true;
            }
        }

        return false;
    }
}
